// https://leetcode.cn/problems/evaluate-reverse-polish-notation/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    int evalRPN(vector<string>& tokens) {
        stack<int> data;
        for (string token : tokens) {
            if (token == "+") {
                int num1 = data.top();
                data.pop();
                int num2 = data.top();
                data.pop();
                data.push(num1 + num2);
            } else if (token == "-") {
                int num1 = data.top();
                data.pop();
                int num2 = data.top();
                data.pop();
                data.push(num2 - num1);
            } else if (token == "*") {
                int num1 = data.top();
                data.pop();
                int num2 = data.top();
                data.pop();
                data.push(num1 * num2);
            } else if (token == "/") {
                int num1 = data.top();
                data.pop();
                int num2 = data.top();
                data.pop();
                data.push(num2 / num1);
            } else {
                int num = stoi(token);
                data.push(num);
            }
        }
        return data.top();
    }
};